<template>
	<div id="zhixun">
		<van-tabs @click="navChange">
			<van-tab v-for='(v,item) in nav' :title="v" :key='item'>
				<van-list v-model="isLoading" :finished="finished" @load="onLoad">
					<div class="lis_warp">
						<van-cell v-for="(v2,index) in adlist" :key="index" :data-id="v2.id?v2.id:index">
							<div class="lis" @click="changeUrl(index,v2.id)" >
								<section :class="[!v2.pic ? 'activeClass' :'adList']">
									<h2>{{v2.title}}</h2>
									<p class="time" v-if="v2.time">{{v2.time}}</p>
									<p class="time" v-else>{{v2.create_time}}</p>
								</section>
								<aside class="imgs" v-show="v2.pic" :style="{backgroundImage: 'url(' + v2.pic + ')'}">
								</aside>
							</div>
						</van-cell>
					</div>
				</van-list>				
			</van-tab>
		</van-tabs>
		<!--footer 组件-->
		<FooTer :Active="2"></FooTer>
	</div>
</template>
<script>
	import Footer from "./common/footer.vue";
	export default {
		// 数据
		data() {
			return {
				nav: ['头条', '公告'],
				adlist: [], //数据
				isLoading: false,
				finished: false,  //控制分页的 没有分页就不用 有就用 
				item: 0, //记录table切换状态   0 是头条 1是公告
			};
		},
		// 当数据发生改变时
		watch: {},
		// 方法
		methods: {
			//刷新执行方法
			onLoad() {
				var _this = this;
				if(_this.adlist.length>0)return false;  //如果有分页就去掉这个限制
				var _this = this;
				_this.getNewsList(_this.item);
				_this.finished = true;  //让onLoad时间触发一次就不要触发
				
				
			},
			//数据请求函数
			getNewsList(index) {
				var _this = this;
				var urls = index == 0 ? _this.$host.NewsList : _this.$host.NoticeList;
				_this.$http.post(urls, {}).then(function(response) {
					_this.adlist = response.data.data
					_this.isLoading = false;

				}).catch(function(error) {})
			},
			//table切换函数
			navChange(index) {
				var _this = this;
				_this.adlist = []; //先清空数据在写数据
				_this.finished = false;
				_this.getNewsList(index);
				_this.item = index;

			},
			//路由跳转函数
			changeUrl(item,id){
				var _this = this;
				var getId = id?id:item;					
				_this.$public.go('zhixundetail',0,_this,{id:getId,what:_this.item});
			}
		},
		// 路由发生变化时
		beforeRouteLeave(to, from, next) {
			next()
		},
		// 加载模块
		components: {
			"FooTer": Footer
		},
		// 加载执行
		created: function() {

		}
	};
</script>